package com.dayuanit.dy15.ebook.bookshop.rabbitmq;

import com.dayuanit.dy15.ebook.bookshop.service.OrderService;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMqHandler {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private OrderService orderService;

    /**
     * 发送消息
     * @param orderId
     */
    public void sendOrderToDealyQueue(Long orderId) {
        rabbitTemplate.convertAndSend("orderExchange", "delayOrderRouting", orderId);
    }

    @RabbitListener(queues = "orderCloseQueue")
    public void receiveCloseOrder(Long orderId) {
        System.out.println("接收要被关闭的订单ID：" + orderId);
        orderService.closeOrder(orderId);
    }


}
